package com.wandian.mvc
{
	import flash.utils.getTimer;

	public class Proxy
	{

		public var data:Object;
		private var _name:String
		public var state:int=1; //0:正在读取,1:读取成功，-1：读取失败
		private var _command:String
		private var _facades:Array=[];
		public var timeStamp:int


		public function Proxy(name:String, command:String)
		{
			this._name=name
			this._command=command;
		}

		public function get name():String
		{
			return _name;
		}

		public function get command():String
		{
			return _command;
		}

		internal function getFacaseIndex(facade:Facade):int
		{
			for (var i:int=0; i < _facades.length; i++)
			{
				var _facade:Facade=this._facades[i] as Facade
				if (facade == _facade)
				{
					return i;
				}
			}
			return -1
		}

		internal function addFacade(facade:Facade):void
		{
			if (getFacaseIndex(facade) > -1)
			{
				return;
			}
			_facades.push(facade);
		}

		internal function removeFacade(facade:Facade):void
		{
			var p:int=getFacaseIndex(facade);
			if (p == -1)
			{
				return;
			}
			_facades.splice(p, 1);
		}

		public function update(postfix:String=""):void
		{
			var command:String=this._command + postfix
			for (var i:int=0; i < _facades.length; i++)
			{
				var facade:Facade=this._facades[i] as Facade
				facade.dispatchAction(this, command, this.data);
			}
		}


	}
}
